package com.gem.day05;

import java.util.Arrays;

/**员工业务类--其中定义了操作员工的CRUD方法*/
public class EmployeeService {
	/**
	 * 添加员工的方法
	 */
	public void addEmp(Employee manager, Employee employee) {
		Employee[] employees = manager.getEmployees();
		if (employees != null) {
			employees = Arrays.copyOf(employees, employees.length + 1);
			employees[employees.length - 1] = employee;
			//把新下属数组设置会manager对象
			manager.setEmployees(employees);
		}
	}

	/**
	 * 输出下属的方法
	 */
	public void printEmp(Employee employee) {
		System.out.println(employee.getName() + "的下属有: ");
		Employee[] employees = employee.getEmployees();
		if (employees != null && employees.length != 0) {
			for (Employee e : employees) {
				System.out.println(e);
			}
		}
	}

	/**
	 * 获取自己下属的人数个数
	 */
	public void countEmp(Employee employee) {
		Employee[] employees = employee.getEmployees();
		int count = 0;
		if (employees != null) {
			count = employees.length;
		}
		System.out.println(employee.getName() + "的下属个数为: " + count);
	}
}
